#include <iostream>
#include <stdlib.h>

#include <nemesis.Logger.h>

#include <nemesis.dbms.Connection.h>

#include <nemesis.dbos.AutoObject.h>

#include <dbos_demo.defines.h>

#include <dbos_demo.oodb.Table01.h>

#include <dbos_demo.phase.UseOneByOne.h>

using namespace std;
using namespace nemesis;
using namespace dbos_demo;

void phase::UseOneByOne::do_comment () const
   throw ()
{
   cout << "Carga y libera N registros, el objetivo es comprobar que una vez que se alcanzan" << endl;
   cout << "el numero maximo de huecos estos se empiezan a re-usar" << endl << endl;
}

void phase::UseOneByOne::do_apply (dbms::Connection& connection)
   throw (RuntimeException, dbms::DatabaseException)
{
   using namespace nemesis::dbms;

   Guard guard (connection);
   
   dbos::AutoObject <oodb::Table01> table01;
   
   int id;
   
   for (int n = 0, maxn = rand () % MaxKey01; n < maxn; n ++) {
      id = rand () % ((MaxKey01 * 120) / 100);
      
      try {
         table01 = oodb::Table01::instanciate (connection, id);
         LOGINFORMATION (
            string msg (nemesis::functions::asString ("%d/%d | ", n, maxn));
            msg += table01->asString ();
            Logger::information (msg, FILE_LOCATION);
         );
      }
      catch (Exception& ex) {
         ex.trace ();
      }
   }
}

 

